﻿using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    public partial class Base_Dic_Option : BaseForm
    {
        BLL.ServiceBase service = new BLL.ServiceBase();
        string TableName = string.Empty;
        string DicNo = string.Empty;
        public Base_Dic_Option(string strTableName, string strDicNo)
        {
            InitializeComponent();
            TableName = strTableName;
            DicNo = strDicNo;
            if (!strTableName.IsNullOrEmptyString() && !strDicNo.IsNullOrEmptyString())
            {
                using (DataTable dt = service.GetDicValue(strTableName, strDicNo))
                {
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        txtDicNo.Text = dt.Rows[0]["DicNO"].ToSafeString();
                        txtDicName.Text = dt.Rows[0]["DicName"].ToSafeString();
                        if (dt.Rows[0]["IsActive"].ToSafeString() == "1")
                        {
                            chkSFYX.Checked = true;
                        }
                        else
                        {
                            chkSFYX.Checked = false;
                        }
                        txtDicNo.Enabled = false;
                    }
                }
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtDicName.Text.ToSafeString().Length == 0)
            {
                DevHelper.ShowErrorMessageBox("请先输入字典值！");
                txtDicName.Focus();
                return;
            }
            string strIsActive = "0";
            if (chkSFYX.Checked)
            {
                strIsActive = "1";
            }
            if (service.SaveDicValue(TableName, txtDicNo.Text, txtDicName.Text, strIsActive))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
